<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="../css/denglu.css">
</head>

<body>
    <div class="top">
        <div class="left">
            <a href="../index.html"><img src="https://book.easou.com/jsp/online/resources/imgs/return.png" alt=""></a>
        </div>
        <div class="zhong">登录</div>
        <div class="right">
            <a href="../index.html"><img src="https://book.easou.com/jsp/online/resources/imgs/home.png" alt=""></a>
        </div>
    </div>
    <div class="zhuce">
        <div class="shuru">
            <input type="text" class="username" placeholder="请输入手机号">
        </div>
        <div class="shuru">
            <input type="password" class="password" placeholder="请输入密码(6-20英文字符、数字)">
        </div>
        <div class="denglu cf"><a href="./zhuce.html" class="register">注册账号</a></div>
        <div class="btn" id="btn">
            登录
        </div>
    </div>

</body>
<script src="../js/jquery.min.js"></script>
<script>
    $("#btn").on("click", function () {
        $.ajax({
            type: "get",
            url: "http://localhost:3000/dengSearch",
            data: {
                phone: $(".username").val(),

            },
            success: function (response) {
                if (response.data.length > 0) {
                    $.ajax({
                        type: "get",
                        url: "http://localhost:3000/denglu",
                        data: {
                            phone: $(".username").val(),
                            password: $(".password").val()
                        },
                        success: function (res) {
                            if (res.data.length > 0) {
                                alert("登录成功");
                                localStorage.setItem("username", $(".username").val())
                                setTimeout(() => {
                                    window.open("../index.html", "_self")
                                }, 1000)
                            }else{
                                alert("账号或者密码错误");
                            }
                        }
                    });
                } else {
                    alert("该手机号未注册，请注册");
                    setTimeout(() => {
                        window.open("./zhuce.html", "_self")
                    }, 1000)
                }
            }
        })
    });
</script>

</html>